<?php
/**
 * Each engineer has a duty to keep the code elegant
 * Created by wolffy.
 * Author @wolffy<13750088090@sina.cn>
 * Date: 2018/12/12
 * Time: 10:25
 */
namespace App\Http\Controllers\BackendApi;

use App\Http\Requests\BackendApi\UserInfoRequest;
use App\Services\BackendApi\InvitedService;
use App\Services\BackendApi\UserService;
use Illuminate\Http\Request;

class InvitedController extends ApiController
{
    protected $invitedService;

    public function __construct(InvitedService $invitedService)
    {
        $this->invitedService = $invitedService;
    }

    public function directBeInvited(Request $request)
    {
        if (empty($request->user_id)) {
            return $this->responseJson(422);
        }
        if (empty($request->level)) {
            $level = 0;
        } else {
            $level = json_decode($request->level);
            if (!is_array($level)) {
                return $this->responseJson(422);
            }
        }
        return $this->invitedService->directBeInvited($request->user_id, $level, $request->page);
    }
}